package com.deepblue.shop.Business.Adapter.HomeAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.deepblue.shop.Business.Model.Home.MenuGoodsModel;
import com.deepblue.shop.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/7/4 0004.
 */
public class MenuGoodsAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<MenuGoodsModel> mMenuGoodsModelArrayList;

    public MenuGoodsAdapter(Context context, ArrayList<MenuGoodsModel> menuGoodsModelArrayList) {
        this.mMenuGoodsModelArrayList = menuGoodsModelArrayList;
        this.mContext = context;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mMenuGoodsModelArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return mMenuGoodsModelArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_menu_goods, null);
            viewHolder.menu_goods_img = (ImageView) convertView.findViewById(R.id.menu_goods_img);
            viewHolder.menu_goods_tv = (TextView) convertView.findViewById(R.id.menu_goods_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        /**
         * 具体的处理在这里
         */
        MenuGoodsModel menuGoodsModel = (MenuGoodsModel) getItem(position);
        viewHolder.menu_goods_tv.setText("hello world!");
        return convertView;
    }

    class ViewHolder {
        ImageView menu_goods_img;
        TextView menu_goods_tv;
    }
}
